﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using LoadingWK;

namespace WindowsFormsTest
{
    public partial class Form1 : Form
    {
        public SameAirplanLoadingClr _sameAirplanLoading = new SameAirplanLoadingClr();
        public MultipleTypeAirplanesLoadingClr _multipleTypeAirplanesLoadingClr = new MultipleTypeAirplanesLoadingClr();
        
        public Form1()
        {
            InitializeComponent();
        }
        
        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;

            _sameAirplanLoading.importInformationOfAirplane(DateSampleFactory.createAirplan_Yun20(), 300.0/*货物最小安全间距*/);
            _sameAirplanLoading.importInformationOfEquipments(DateSampleFactory.createEquipmentList());
            
            _sameAirplanLoading.setStepOfOffsetLoad(10/*超级装载时平移步长，10cm*/);

            int countOfLoadedAirplanes = _sameAirplanLoading.startLoadingWithMaxCountOfAirplane(10);
            List<LoadedAirplaneClr> loadedAirplaneClrs = _sameAirplanLoading.getLoadedAirplanes();
            
            LoadedEquipmentListClr loadedEquipmentList = _sameAirplanLoading.getLoadedEquipments();
            List<EquipmentClr> unloadedEquipments = _sameAirplanLoading.getUnloadedEquipments();
            updateTextEditContent(loadedEquipmentList,_sameAirplanLoading.getStepOfOffsetLoad());
            updateTextOfLoadAirplanes(loadedAirplaneClrs, _sameAirplanLoading.getStepOfOffsetLoad());
            updateTextOfUnloadedEuqipments(unloadedEquipments);
        }
        private void button_MultTypes_Click(object sender, EventArgs e)
        {
            button_MultTypes.Enabled = false;

            _multipleTypeAirplanesLoadingClr.importAirplaneList(DateSampleFactory.createAirplanList(), 300.0/*货物最小安全间距*/);
            _multipleTypeAirplanesLoadingClr.importEquipmentsList(DateSampleFactory.createEquipmentList());

            _multipleTypeAirplanesLoadingClr.setStepOfOffsetLoad(20/*超级装载时平移步长，10cm*/);

            int countOfLoadedAirplanes = _multipleTypeAirplanesLoadingClr.startLoading();
            List<LoadedAirplaneClr> loadedAirplaneClrs = _multipleTypeAirplanesLoadingClr.getLoadedAirplanes();

            LoadedEquipmentListClr loadedEquipmentList = _multipleTypeAirplanesLoadingClr.getLoadedEquipments();
            List<EquipmentClr> unloadedEquipments = _multipleTypeAirplanesLoadingClr.getUnloadedEquipments();
            updateTextEditContent(loadedEquipmentList, _multipleTypeAirplanesLoadingClr.getStepOfOffsetLoad());
            updateTextOfLoadAirplanes(loadedAirplaneClrs, _multipleTypeAirplanesLoadingClr.getStepOfOffsetLoad());
            updateTextOfUnloadedEuqipments(unloadedEquipments);
        }
        
        private void updateTextEditContent(LoadedEquipmentListClr loadedEquipmentList, double stepOfOff)
        {
            string content = "平移步长：" + stepOfOff.ToString() + " mm\r\n";
            content += "所需飞机总数：" + loadedEquipmentList.getCountOfLoadedAirplane().ToString() + "\r\n";
            foreach(LoadedEquipmentClr equ in loadedEquipmentList._loadedEquipmentList)
            {
                content += "equipmentID: " + equ._idOfEquipment.ToString() ;
                content += " airplanType:" + equ._typeIDOfAirplane.ToString();
                content += " airplanIndex:" + equ._indexOfLoadedAirplane.ToString();
                content += " Y:" + equ._leftY_Equipment.ToString();
                content += "\r\n";
            }
            textEditContent.Text = content;
        }
        private void updateTextOfUnloadedEuqipments(List<EquipmentClr> unloadedEquipments)
        {
            string content = "未被装载装备ID 清单: { ";
            foreach (EquipmentClr unEqu in unloadedEquipments)
            {
                content += unEqu._id.ToString() + " , ";
            }
            content += "}\r\n";
            textBox_UnloadedEquipments.Text = content;
        }
        private void updateTextOfLoadAirplanes(List<LoadedAirplaneClr> loadedAirplanes, double stepOfOff)
        {
            string content = "平移步长：" + stepOfOff.ToString() + " mm\r\n";
            content += "所需飞机总数：" + loadedAirplanes.Count.ToString() + "\r\n";
            foreach (LoadedAirplaneClr air in loadedAirplanes)
            {
                content += " airplanType:" + air._typeID.ToString();
                content += " airplanIndex:" + air._loadedIndex.ToString();
                content += "\r\n";
                foreach (LoadedEquipmentClr equ in air._loadedEquipments)
                {
                    content += "    equipmentID: " + equ._idOfEquipment.ToString();
                    content += " Y:" + equ._leftY_Equipment.ToString();
                    content += "\r\n";
                }
            }
            textBox_AirplaneState.Text = content;
        }

        private void button_Refresh_Click(object sender, EventArgs e)
        {
            textBox_UnloadedEquipments.Text = "";
            textBox_AirplaneState.Text = "";
            textEditContent.Text = "";
            button1.Enabled = true;
            button_MultTypes.Enabled = true;
        }
    }
}
